package com.tiemei.demo.client.tair;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.taobao.tair.DataEntry;
import com.taobao.tair.Result;
import com.taobao.tair.ResultCode;
import com.taobao.tair.impl.mc.MultiClusterTairManager;

/**
 * Trident tair client, Run directly!
 * 
 * @author tiemei.jdk
 * @date 2012-9-29
 */
public class TairClient {

	private static MultiClusterTairManager mcTairManager;

	private static final int namespace = 16;

	private static final String KEYPREFIX_UDC = "features_dsr";

	private static final String SPLIT = "$";
	static {
		mcTairManager = new MultiClusterTairManager();
		mcTairManager.setConfigID("mdbcomm-daily");
		mcTairManager.setDynamicConfig(true);
		mcTairManager.init();
	};

	// 批量获取方法,可以看到我们存在tair中的最原始数据
	public static void batchGet(List<Serializable> keys) {
		Result<List<DataEntry>> result = mcTairManager.mget(namespace, keys);
		if (result.isSuccess() || ResultCode.PARTSUCC.equals(result.getRc())) {
			List<DataEntry> entrys = result.getValue();
			if (entrys != null && entrys.size() > 0) {
				for (DataEntry entry : entrys) {
					System.out.println("reuslt:" + entry.getValue());
				}
			}
		}
	}
	
	// remove
	public static void removeOneKey (String key) {
		mcTairManager.put(namespace, key, "");
	}
	

	public static void main(String args[]) {
		
		batchGet(new ArrayList<Serializable>() {
			{
				add(KEYPREFIX_UDC + SPLIT + "2062279930");
			}
		});
	}
}
